﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Registro.Compras.Data.Entities;

namespace Registro.Compras.Data.Business
{
    public class ElementoBusiness
    {
        public static IList<Elemento> GetListByFilter(string filter)
        {
            using (RegistroComprasDbContext ctx = new RegistroComprasDbContext())
            {
                return ctx.Elementos.Where(u => u.Descripcion.Contains(filter)).ToList();
            }
        }
        public static Elemento GetById(int id)
        {
            using (RegistroComprasDbContext ctx = new RegistroComprasDbContext())
            {
                Elemento ElementoDB = ctx.Elementos.Find(id);
                if (ElementoDB == null)
                {
                    throw new Exception("Elemento not found in data base");
                }
                return ElementoDB;
            }
        }
    }
}